﻿using System;
using System . Collections . Generic;
using System . Linq;
using System . Text;
using System . Xml . Linq;

namespace WenceyWang . RichMan4L . Maps
{
	public class WithInRoad : NormalRoad
	{
		long inRoadID;

		Road inRoad = null;

		public virtual Road InRoad { get { return inRoad ?? ( inRoad = Map . Currnet . GetRoad ( inRoadID ) ); } set { inRoadID = value . Id; inRoad = value; } }

		public override Path Route ( Road previous , int moveCount , Path result = null )
		{
			if ( previous == InRoad )
			{
				Path current = result ?? new Path ( );
				current . Route . Add ( this );
				if ( BlockMoving || moveCount == 0 )
				{
					return current;
				}
				Random random = new Random ( );
				switch ( random . Next ( 0 , 2 ) )
				{
					case 0:
						{
							return ForwardRoad . Route ( this , moveCount - 1 , result );

						}
					case 1:
						{
							return BackwardRoad . Route ( this , moveCount - 1 , result );
						}
					default:
						{
							throw new NotImplementedException ( );
						}
				}
			}
			else
			{
				return base . Route ( previous , moveCount , result );
			}
		}

		public WithInRoad ( XElement resource ) : base ( resource )
		{
			inRoadID = Convert . ToInt64 ( resource . Attribute ( nameof ( InRoad ) ) . Value );
		}

	}
}
